/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-09-10 18:26:40
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-11-19 17:09:05
 * @FilePath: \project\work-tool\experi-api\routes\users.js
 * @Description: 
 */
var express = require('express');
var router = express.Router();
const Model = require('../models/ListModel')
const fs = require('fs');

// 读取custom文件
const customFile = './routes/custom/index.js'

fs.readFile(customFile, 'utf8', (err, data)=> {
  if (err) {
    console.error('err---', err);
    return;
  }
  // console.log(data, router)
  
  // const customContent = data + `router.post('/create/api', (req, res, next)=> {
  //   return res.send('123');})`
  
  // fs.writeFile(customFile, customContent, (err)=> {
  //   if (err) {
  //     console.error('err---', err);
  //     return;
  //   }
  //   console.log('写入成功')
  // })
  
})

// console.log('router', router)

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.send('respond with a resource');
});

router.post('/login', async (req, res, next) => {
  const { userName, password } = req.body
  const result = await Model.find({userName, password})
  console.log('%c [ result ]-47',  result)
  if(result.length) {
    return res.send({
      code: 200,
      msg: '登录成功'
    })
  } else {
    return res.send({
      code: 500,
      msg: '登录失败'
    })
  }
  
})

router.post('/create/api', function(req, res, next) {
  return res.send('123');
})



module.exports = router;
